package com.gitee.qdbp.general.mgr.controller.trade;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.gitee.qdbp.able.exception.ServiceException;
import com.gitee.qdbp.able.jdbc.ordering.OrderPaging;
import com.gitee.qdbp.able.jdbc.paging.PageList;
import com.gitee.qdbp.able.result.ResponseMessage;
import com.gitee.qdbp.base.annotation.OperateRecord;
import com.gitee.qdbp.base.enums.OperateType;
import com.gitee.qdbp.base.system.model.IAccount;
import com.gitee.qdbp.base.utils.EnumTools;
import com.gitee.qdbp.base.utils.SessionTools;
import com.gitee.qdbp.general.trade.api.order.main.model.OrderFormBean;
import com.gitee.qdbp.general.trade.api.order.main.model.OrderFormWhere;
import com.gitee.qdbp.general.trade.api.order.main.service.IOrderMainQueryer;
import com.gitee.qdbp.general.trade.enums.OrderState;
import com.gitee.qdbp.general.trade.enums.OrderType;

/**
 * 个人捐款订单管理控制器
 *
 * @author zhaohuihua
 * @version 180628
 */
@Controller
@RequestMapping("actions/my-order/donate")
public class MyDonateOrderController {

    @Autowired
    private IOrderMainQueryer orderMainQueryer;

    @ResponseBody
    @RequestMapping("list")
    @OperateRecord(value = "个人捐款订单:查询", type = OperateType.QUERY)
    public ResponseMessage list(OrderFormWhere model, OrderPaging paging, Boolean extra) {
        try {
            IAccount me = SessionTools.getLoginUser();
            model.setOrderType(OrderType.DONATE);
            model.setUserId(me.getId());
            PageList<OrderFormBean> list = orderMainQueryer.list(model, paging);
            ResponseMessage result = new ResponseMessage(list);
            if (Boolean.TRUE.equals(extra)) {
                result.addExtra(EnumTools.getEnumsResource(OrderState.class));
            }
            return result;
        } catch (ServiceException e) {
            return new ResponseMessage(e);
        }
    }

}
